package com.htjx.mall.commons.utils;

import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 数据格式校验
 * 
 * @author jingrenlang
 * 
 */
public class Checks {

	public static boolean isEmail(String email) {
		boolean tag = true;
		final String pattern1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		final Pattern pattern = Pattern.compile(pattern1);
		final Matcher mat = pattern.matcher(email);
		if (!mat.find()) {
			tag = false;
		}
		return tag;

	}

	public final static boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[0-9])|(17[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	public static boolean isIdCardNo(String idcard) {
		String result = IdCardChecker.check(idcard);
		return result.equals("");
	}

	public static boolean isInteger(String number) {    
		Pattern pattern = Pattern.compile("^[\\+]?[\\d]*$");    
		return pattern.matcher(number).matches();    
	}  
	
	public static boolean isPassword(String password){
		//String reg = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
		String reg = "^[0-9A-Za-z\\`\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\=\\+\\[\\]\\{\\}\\;\\:\\'\\\"\\<\\>\\?\\/\\\\\\|\\,\\.\\?]{6,16}$";
		Pattern pattern = Pattern.compile(reg);
		Matcher mat = pattern.matcher(password);
		if(mat.find()){
			return true;
		}
		return false;
	}
	
	public static boolean checkDateFormat(String date){
		try{
			SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
			format.parse(date);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
}
